package com.dragon.logical.service.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.ResultCode;
import com.dragon.common.model.exception.CustomException;
import com.dragon.repository.entity.TechnicalPerson;
import com.dragon.repository.mapper.TechnicalPersonMapper;
import com.dragon.logical.service.customer.ITechnicalPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 技术联系人表 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-07-05
 */
@Service
public class TechnicalPersonServiceImpl extends ServiceImpl<TechnicalPersonMapper, TechnicalPerson> implements ITechnicalPersonService {

    @Autowired
    TechnicalPersonMapper mapper;

    @Override
    public Page<TechnicalPerson> technicalList() {
        return mapper.selectPage(new Page<TechnicalPerson>(),null);
    }

    @Override
    public void addTechnical(TechnicalPerson technical) {
        TechnicalPerson technicalPerson = mapper.selectOne(new QueryWrapper<TechnicalPerson>().lambda().eq(TechnicalPerson::getTechnicalName, technical.getTechnicalName()));
        if (technicalPerson != null){
            throw new CustomException(ResultCode.DATA_ALREADY_EXISTS);
        }
        mapper.insert(technical);
    }

    @Override
    public void updateTechnical(TechnicalPerson convert) {
        mapper.updateById(convert);
    }

    @Override
    public void deleteTechnical(Integer id) {
        mapper.deleteById(id);
    }
}
